<!DOCTYPE html>
<html lang="en">

<head>
  <title>详细示例</title>
  <script src="https://c.qcc.com/qcc_components.js?be46096145b84860ae01a86062a9863e"></script>
  <script src="layui/layui.js"></script>
  <link rel="stylesheet" href="layui/css/layui.css" media="all">
  <style>
  </style>
</head>

<body>
  <div id="qcc_sdk" style="margin: 20px 20px;"></div>
  <div id="show" style="margin: 20px 20px;">
    <form class="layui-form" action="" lay-filter="example">
      <div class="layui-form-item"> <label class="layui-form-label">企业名称</label>
        <div class="layui-input-block">
          <input type="text" name="name" lay-verify="title" autocomplete="off" class="layui-input" disabled>
        </div>
      </div>

      <div class="layui-form-item"> <label class="layui-form-label">统一社会信用代码</label>
        <div class="layui-input-block">
          <input type="text" name="creditCode" lay-verify="title" autocomplete="off" class="layui-input" disabled>
        </div>
      </div>

      <div class="layui-form-item"> <label class="layui-form-label">成立日期</label>
        <div class="layui-input-block">
          <input type="text" name="startDate" lay-verify="title" autocomplete="off" class="layui-input" disabled>
        </div>
      </div>

      <div class="layui-form-item"> <label class="layui-form-label">法定代表人姓名</label>
        <div class="layui-input-block">
          <input type="text" name="operName" lay-verify="title" autocomplete="off" class="layui-input" disabled>
        </div>
      </div>

      <div class="layui-form-item"> <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
          <input type="text" name="status" lay-verify="title" autocomplete="off" class="layui-input" disabled>
        </div>
      </div>

      <div class="layui-form-item"> <label class="layui-form-label">注册号</label>
        <div class="layui-input-block">
          <input type="text" name="no" lay-verify="title" autocomplete="off" class="layui-input" disabled>
        </div>
      </div>
      <div class="layui-form-item layui-form-text"> <label class="layui-form-label">注册地址</label>
        <div class="layui-input-block"> <textarea class="layui-textarea" name="address" disabled></textarea>
        </div>
      </div>

    </form>
  </div>
  </div>
  <script>


    layui.use(['form'], function () {
      var form = layui.form;

      var $ = layui.jquery

        //渲染数据
        window.show = function (json) {
        form.val('example', JSON.parse(json));
        }


        //ajax   调取企业查询接口，使用企查查的，  利用sdk快速找到公司名称，然后后台包装的接口调取企查查的高级搜索功能匹配准确的公司名字
        window.getData = function(name) {
          $.ajax({
				  "url":"http://localhost:8080/queryInfo?name=" + name,
				  "type":"get",
				  "data":"t=tiobe",
				  "dataType":"json",  
				  "success":function(json){
            form.val('example', json);
				},
          "error":function(xmlhttp,errorText){    
            console.log(xmlhttp);
            console.log(errorText);
            if(xmlhttp.status == "405"){
              alert("无效的请求方式");
            }else if(xmlhttp.status == "404"){
              alert("未找到url资源");
            }else if(xmlhttp.status == "500"){
              alert("服务器内部错误");
            }else{
              alert("其他异常");
            }
            
          }
			});
        }
    });

    document.addEventListener('DOMContentLoaded', function () {
      window.QCC.init({
        el: 'qcc_sdk',
        placeholder: '请输入您想要搜索的企业关键字',
        onSelect: (data) => {
         
          //获取数据
          var json = getData(data.companyName);
        }
      })
    }, false);

   



  </script>
</body>

</html>